# 导包
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
# 导入键盘操作类，包含特殊的键
from selenium.webdriver.common.keys import Keys

# 获取浏览器驱动
driver = webdriver.Firefox()
driver.maximize_window()
# 打开测试的网址
url = 'file:///C:/Users/tedu/Desktop/NSD2407/html/registerA.html'
driver.get(url)

username = driver.find_element(By.CSS_SELECTOR, '#userA')
# 在用户名文本框中输入admin1
username.send_keys('admin1')
# 执行退格，删除最后1
sleep(3)
username.send_keys(Keys.BACKSPACE)
# 全选操作
sleep(3)
username.send_keys(Keys.CONTROL, 'a')
# 执行CTRL+c
username.send_keys(Keys.CONTROL, 'c')
# 在密码框中执行ctrl+v
password = driver.find_element(By.CSS_SELECTOR, '#passwordA')
sleep(3)
password.send_keys(Keys.CONTROL, 'v')
sleep(3)
# 执行回车
password.send_keys(Keys.ENTER)

# 停顿3秒，关闭浏览器
sleep(3)
driver.quit()